<template>
    <div class="app-container">
        <wms-form v-model="queryParams" :form-list="formList" @query="getList" @export="handleExport">
        </wms-form>
        <wms-table :loading="loading" :data-list="stockList" :column="column" :pageInfo="queryParams" @get-list="getList" @selection-change="handleSelectionChange"/>
    </div>
</template>

<script setup name="StockDialog">
import {
  checkListStock,
    disablesStock // 新增的冻结/解冻API
} from "@/api/wms/stock.js";
import WmsForm from '@/components/WmsForm/index.vue'
import WmsTable from '@/components/WmsTable/index.vue'
// 固定字段初始化
import { data, column, formList } from './index.js'
const dataReactive = reactive(data);
const { queryParams, form, rules } = toRefs(dataReactive);
// end

import { ElMessage, ElMessageBox } from "element-plus"; // 导入Element Plus消息组件
const { proxy } = getCurrentInstance();
const { wms_common_status,wms_stock_status,stock_lock_status,wms_quality_status } = proxy.useDict('wms_common_status','wms_stock_status','stock_lock_status','wms_quality_status');

const stockList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const title = ref("");
const selectedStocks = ref([]);
/** 查询库存查询列表 */
function getList() {
    loading.value = true;
    checkListStock(proxy.addDateRange(queryParams.value, queryParams.value.dateRange)).then(response => {
        stockList.value = response.rows;
        queryParams.value.total = response.total;
        loading.value = false;
    });
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}

/** 重置按钮操作 */
function resetQuery() {
    queryParams.value.dateRange = [];
    proxy.resetForm("queryRef");
    handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.stockId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
    selectedStocks.value = selection;
}

// 暴露选中的库存项
defineExpose({
  getSelectedStocks: () => selectedStocks.value
})

/** 导出按钮操作 */
function handleExport() {
    proxy.download('${moduleName}/${businessName}/export', {
        ...queryParams.value
    }, `${businessName}_#[[${new Date().getTime()}.xlsx`)
}

getList();

const switchChange = (status, row) => {
  // 修改状态接口
  row.isActive = status;
};
</script>
